//
//  HT_DataDownloadTools.m
//  UILesson17_imageDownloader
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 韩婷婷. All rights reserved.
//

#import "HT_DataDownloadTools.h"

@implementation HT_DataDownloadTools
+(void)downloadDataWithURL:(NSString *)urlString andMethod:(NSString *)method andBody:(NSString *)body andBlock:(OptionBlock )block{
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
    //有没有更好的方式忽略大小写进行比较
    if ([method caseInsensitiveCompare:@"post"] == NSOrderedSame) {
        //这里就添加一项post方式需要设置的方式
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
    }
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        block(data);
    }];
 //block的主要功能就是代码段传递
}

@end
